//
//  WmcFunctionSelectCell.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/3/14.
//

import UIKit
import YPBedrock

extension WmcFunctionSelectCell {
    class Model {
        // Lifecycle

        init(title: String,
             width: CGFloat = 35,
             isUseSelect: Bool = true,
             didSelectBlock: YPBlock.OneParam<Model>? = nil)
        {
            self.title = title
            self.width = width
            self.isUseSelect = isUseSelect
            self.didSelectBlock = didSelectBlock
        }

        // Internal

        var title: String = ""
        var width: CGFloat = 35
        var isSelect: Bool = false // 选中状态
        var isUseSelect: Bool = true // 是否可以被选中，如果不能被选中，则只会回调Block
        var didSelectBlock: YPBlock.OneParam<Model>?
    }
}

// MARK: - [WmcFunctionSelectCell]

class WmcFunctionSelectCell: WmcBaseCollectionCell {
    lazy var pointView: UIView = {
        let view = UIView()
        view.backgroundColor = .wmc_grayH2_323233
        view.layer.cornerRadius = 2
        view.layer.masksToBounds = true
        view.isHidden = true
        return view
    }()

    var isTransparent: Bool = false

    override func makeUI() {
        titleLabel.textAlignment = .center
        titleLabel.textColor = .wmc_grayH2_323233
        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(4)
            make.left.right.equalToSuperview()
        }

        addSubview(pointView)
        pointView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(titleLabel.snp.bottom).offset(4)
            make.size.equalTo(4)
        }
    }

    func configModel(_ model: Model) {
        titleLabel.text = model.title

        pointView.isHidden = !model.isSelect
        if isTransparent { // 透明
            pointView.backgroundColor = .white
        } else {
            pointView.backgroundColor = .wmc_grayH2_323233
        }
        if model.isSelect {
            if isTransparent { // 透明
                titleLabel.textColor = .white
            } else {
                titleLabel.textColor = .wmc_grayH2_323233
            }
            titleLabel.font = 15.yp.uiFont(weight: .medium)
        } else {
            if isTransparent { // 透明
                titleLabel.textColor = .white
            } else {
                titleLabel.textColor = .wmc_grayH8_8A8A99
            }
            titleLabel.font = 15.yp.uiFont(weight: .regular)
        }
    }
}
